/*
 *  uiImage.cpp
 *  trail-map-editor
 *
 *  Created by Giorgio Tino on 2/28/13.
 *  Copyright 2013 __MyCompanyName__. All rights reserved.
 *
 */

#include "ui.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

uiImage::uiImage() 
: hidden(false)
, width(0.0f)
, height(0.0f)
, texture(0)
{
}

uiImage::uiImage(const char *name, const float width, const float height)
: hidden(false)
, width(0.0f)
, height(0.0f)
, texture(0)
{
    this->width = width;
    this->height = height;
	
	this->texture = uiTextureManager::getInstance().getTexture(name);
}

uiImage::~uiImage()
{
	// Do not delete the texture
}

void uiImage::draw(const float x, const float y)
{    
	this->update();
	
	if(this->hidden)
		return;
	 
	// Draw the texture!!!
	glEnable(GL_TEXTURE_2D);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glBindTexture(GL_TEXTURE_2D, texture->getHandle());
	glBegin(GL_QUADS);
    glTexCoord2f(texture->left, texture->top); glVertex2f(x, y);
	glTexCoord2f(texture->left, texture->bottom); glVertex2f(x, y + height);
	glTexCoord2f(texture->right, texture->bottom); glVertex2f(x + width, y + height);
	glTexCoord2f(texture->right, texture->top); glVertex2f(x + width, y);
	glEnd();
	glDisable(GL_TEXTURE_2D);
}

//bool uiImage::hitTest(int b, int s, int xCoord, int yCoord)
//{	
//	return (x <= xCoord) && (y <= yCoord) && (xCoord <= (x + width)) && (yCoord <= (y + height));
//}	


